module Tuscan
  module Iec60584
    module TypeT
      T90_RANGE = -270.0..400.0 
      EMF_RANGE = -5.603..20.872 

      extend self

      def emfr_unbound t90
        if t90 < 0.0
          Polynomial.new(
             0.000000000000e+00,  0.387481063640e-01,  0.441944343470e-04,  0.118443231050e-06,
             0.200329735540e-07,  0.901380195590e-09,  0.226511565930e-10,  0.360711542050e-12,
             0.384939398830e-14,  0.282135219250e-16,  0.142515947790e-18,  0.487686622860e-21,
             0.107955392700e-23,  0.139450270620e-26,  0.797951539270e-30
          ).solve_for t90
        else
          Polynomial.new(
             0.000000000000e+00,  0.387481063640e-01,  0.332922278800e-04,  0.206182434040e-06,
            -0.218822568460e-08,  0.109968809280e-10, -0.308157587720e-13,  0.454791352900e-16,
            -0.275129016730e-19
          ).solve_for t90
        end
      end

      def t90r_guess emf
        if emf < 0.0
          Polynomial.new(
             0.0000000e+00,  2.5949192e+01, -2.1316967e-01,  7.9018692e-01,  4.2527777e-01, 
             1.3304473e-01,  2.0241446e-02,  1.2668171e-03
          ).solve_for emf
        else
          Polynomial.new(
             0.000000e+00,   2.592800e+01,  -7.602961e-01,   4.637791e-02,  -2.165394e-03,
             6.048144e-05,  -7.293422e-07
          ).solve_for emf
        end
      end
    end
  end
end
